<?php
/**
 * VideopianCompatibilityMatrix
 * compatibility reference for Videopian
 *
 * -------------------------------------------------------------------
 * NEW BSD LICENSE
 *
 * Copyright (C) 2009-2010 Upian.com and contributors
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * - Redistributions of source code must retain the above copyright notice,
 *   this list of conditions and the following disclaimer.
 *
 * - Redistributions in binary form must reproduce the above copyright notice,
 *   this list of conditions and the following disclaimer in the documentation
 *   and/or other materials provided with the distribution.
 *
 * - Neither the name of Upian.com nor the names of its
 *   contributors may be used to endorse or promote products derived from this
 *   software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * -------------------------------------------------------------------
 *
 * @author Denis Hovart <denis@upian.com>
 * @author Hans Lemuet <hans@upian.com>
 * @license http://opensource.org/licenses/bsd-license.php New BSD license
 * @version 0.2
 */

class VideopianField {

	public $name,$type,$required;

	function VideopianField($name, $type, $required = false) {

		$this->name = $name;
		$this->type = $type;
		$this->required = $required;

	}

}

class VideopianService {

	public $name,$type,$fields,$required,$hidden;

	function VideopianService($name, $url, $fields = array(), $api_key_required = false, $hidden = false) {

		$this->name = $name;
		$this->url = $url;
		$this->fields = $fields;
		$this->api_key_required = $api_key_required;
		$this->hidden = $hidden;

	}

}

class VideopianCompatibilityMatrix {

	public $fields;
	public $services;

	function VideopianCompatibilityMatrix() {

		$this->fields = array(

			'url'				=> new VideopianField('URL', 'string', true),
			'site'				=> new VideopianField('Service', 'string', true),
			'title'				=> new VideopianField('Title', 'string'),
			'description'		=> new VideopianField('Description', 'string'),
			'tags'				=> new VideopianField('Tags', 'array'),
			'duration'			=> new VideopianField('Duration', 'int'),
			'width'				=> new VideopianField('Width', 'int'),
			'height'			=> new VideopianField('Height', 'int'),
			'author'			=> new VideopianField('Author name', 'string'),
			'author_url'		=> new VideopianField('Author URL', 'string'),
			'date_published'	=> new VideopianField('Publication date', 'DateTime'),
			'date_updated'		=> new VideopianField('Last update date', 'DateTime'),
			'thumbnails'		=> new VideopianField('Thumbnails', 'array'),
			'player'			=> new VideopianField('Player URL', 'string'),
			'files'				=> new VideopianField('Files URL', 'array'),
			'thumbnails'		=> new VideopianField('Thumbnails', 'array'),
			'xml_url'			=> new VideopianField('URL XML data', 'string', true),

		);

		$this->services = array(

			'blip'				=> new VideopianService('Blip', 'http://www.blip.tv', array_merge($this->getFieldsArray(), array(
				'title'				=> 'y',
				'description'		=> 'y',
				'tags'				=> 'y',
				'duration'			=> 'y',
				'width'				=> 'y',
				'height'			=> 'y',
				'author'			=> 'y',
				'author_url'		=> 'y',
				'date_published'	=> 'y',
				'date_updated'		=> 'n',
				'thumbnails'		=> 'y',
				'player'			=> 'y',
				'files'				=> 'y',
				'thumbnails'		=> 'y'
			))),

			'dailymotion'		=> new VideopianService('Dailymotion', 'http://www.dailymotion.com', array_merge($this->getFieldsArray(), array(
				'title'				=> 'y',
				'description'		=> 'y',
				'tags'				=> 'y',
				'duration'			=> 'y',
				'width'				=> 'y',
				'height'			=> 'y',
				'author'			=> 'y',
				'author_url'		=> 'y',
				'date_published'	=> 'y',
				'date_updated'		=> 'n',
				'thumbnails'		=> 'y',
				'player'			=> 'y',
				'files'				=> 'y',
				'thumbnails'		=> 'y'
			))),

			'flickr'			=> new VideopianService('Flickr', 'http://www.flickr.com', array_merge($this->getFieldsArray(), array(
				'title'				=> 'y',
				'description'		=> 'y',
				'tags'				=> 'y',
				'duration'			=> false,
				'width'				=> null,
				'height'			=> null,
				'author'			=> 'y',
				'author_url'		=> 'y',
				'date_published'	=> 'y',
				'date_updated'		=> 'y',
				'thumbnails'		=> 'y',
				'player'			=> 'y',
				'files'				=> 'y',
				'thumbnails'		=> 'y'
			)), true),

			'googlevideo'		=> new VideopianService('Google Video', 'http://video.google.com', array_merge($this->getFieldsArray(), array(
				'title'				=> 'y',
				'description'		=> 'n',
				'tags'				=> 'n',
				'duration'			=> 'y',
				'width'				=> null,
				'height'			=> null,
				'author'			=> 'n',
				'author_url'		=> 'n',
				'date_published'	=> 'y',
				'date_updated'		=> 'n',
				'thumbnails'		=> 'y',
				'player'			=> 'y',
				'files'				=> 'y',
				'thumbnails'		=> 'y'
			))),

			'metacafe'			=> new VideopianService('Metacafe', 'http://www.metacafe.com', array_merge($this->getFieldsArray(), array(
				'title'				=> 'y',
				'description'		=> 'y',
				'tags'				=> 'y',
				'duration'			=> 'n',
				'width'				=> null,
				'height'			=> null,
				'author'			=> 'y',
				'author_url'		=> 'y',
				'date_published'	=> 'y',
				'date_updated'		=> 'n',
				'thumbnails'		=> 'y',
				'player'			=> 'y',
				'files'				=> 'n',
				'thumbnails'		=> 'y'
			))),

			'myspace'			=> new VideopianService('MySpace', 'http://www.myspace.com', array_merge($this->getFieldsArray(), array(
				'title'				=> 'y',
				'description'		=> 'n',
				'tags'				=> 'n',
				'duration'			=> 'n',
				'width'				=> null,
				'height'			=> null,
				'author'			=> null,
				'author_url'		=> null,
				'date_published'	=> 'y',
				'date_updated'		=> 'n',
				'thumbnails'		=> 'y',
				'player'			=> 'y',
				'files'				=> 'y',
				'thumbnails'		=> 'y'
			))),

			'veoh'			=> new VideopianService('Veoh', 'http://www.veoh.com', array_merge($this->getFieldsArray(), array(
				'title'				=> 'y',
				'description'		=> 'y',
				'tags'				=> 'y',
				'duration'			=> 'y',
				'width'				=> null,
				'height'			=> null,
				'author'			=> 'y',
				'author_url'		=> 'y',
				'date_published'	=> 'y',
				'date_updated'		=> 'n',
				'thumbnails'		=> 'y',
				'player'			=> 'y',
				'files'				=> 'y',
				'thumbnails'		=> 'y'
			)), true),

			'viddler'			=> new VideopianService('Viddler', 'http://www.viddler.com', array_merge($this->getFieldsArray(), array(
				'title'				=> null,
				'description'		=> null,
				'tags'				=> null,
				'duration'			=> null,
				'width'				=> null,
				'height'			=> null,
				'author'			=> null,
				'author_url'		=> null,
				'date_published'	=> null,
				'date_updated'		=> null,
				'thumbnails'		=> null,
				'player'			=> null,
				'files'				=> null,
				'thumbnails'		=> null,
				'xml_url'			=> null
			)), true),

			'vimeo'			=> new VideopianService('Vimeo', 'http://www.vimeo.com', array_merge($this->getFieldsArray(), array(
				'title'				=> 'y',
				'description'		=> 'y',
				'tags'				=> 'y',
				'duration'			=> 'y',
				'width'				=> null,
				'height'			=> null,
				'author'			=> 'y',
				'author_url'		=> 'y',
				'date_published'	=> 'y',
				'date_updated'		=> 'n',
				'thumbnails'		=> 'y',
				'player'			=> 'y',
				'files'				=> null,
				'thumbnails'		=> 'y'
			))),

			'youtube'			=> new VideopianService('YouTube', 'http://www.youtube.com', array_merge($this->getFieldsArray(), array(
				'title'				=> 'y',
				'description'		=> 'y',
				'tags'				=> 'y',
				'duration'			=> 'y',
				'width'				=> null,
				'height'			=> null,
				'author'			=> 'y',
				'author_url'		=> 'y',
				'date_published'	=> 'y',
				'date_updated'		=> 'y',
				'thumbnails'		=> 'y',
				'player'			=> 'y',
				'files'				=> null,
				'thumbnails'		=> 'y'
			))),
			
		);

	}

	public function fields($value = false) {

		if ($value) {$this->fields = $value; return;}

		return $this->fields;

	}

	public function services($value = false) {

		if ($value) {$this->services = $value; return;}

		return $this->services;

	}

	private function getFieldsArray() {
		$array = array_fill_keys(array_keys($this->fields),false);

		foreach ($array as $k => &$v) {
			if ($this->fields[$k]->required) $v = 'y';
		}

		return $array;
	}

	function getHtmlCell($value) {

		if (is_null($value)) return '<td class="del">&ndash;</td>';

		switch ($value) {
			case 'y':
				return '<td class="yes">&bull;</td>';
				break;

			case 'n':
				return '<td class="no">&times;</td>';
				break;

			case false:
				return '<td class="del">?</td>';
				break;
		}

	}

}
?>
